home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / amos / amoslist-0295.lzh / AMOSLIST / text0050.txt < prev    next >
Encoding:
Text File  |  1995-03-01  |  1.9 KB  |  78 lines

  1. Forwarded Message:
  2. From: MenTaT - !Productions <mentat@sefl.satelnet.org>
  3. Date: Tue, 31 Jan 1995 15:30:31 -0500 (EST)
  4. Subject: Re: Recursive programming (Re: Paint, et all.)
  5. To: "stud.ass." <bcollin@mpi.nl>
  6.  
  7. > > How does recursive programming work? Suppose I wanted to make a 
  8. > > MineSweeper clone, how would I let the computer show all the
  9. > > fields that aren't surrounded by a bomb whenever I hit a field
  10. > > which is not surrounded by a bomb? 
  11. > > Mind, I'm not trying to make a clone here, I just thought it's
  12. > > the best way to illustrate whatever I try to... well, er, try,
  13. > > really :)
  14. > > 
  15. > Recursive programming works by calling a procedure from itself.
  16. > i.e.:
  17. > Procedure Test[A]
  18. >   Inc A
  19. >   If A<10 Then Test[A]
  20. > End proc
  21. > I am not sure this example will work in Amos, though. I seem to 
  22. > remember that Amos has some limitations on recursion, for 
  23. instance 
  24. > that the procedure calls may not be nested more than 15 times, 
  25. > which makes it useless for most applications.
  26.  
  27. You need to do a Set Buffer (or something similar).  I wrote an 
  28. ATOMS 
  29. clone once, and occasionally it would get about 3 or 4 thousand 
  30. levels 
  31. deep. :)
  32.  
  33. > BTW, why would you want to use recursion for this Mines-clone. 
  34. You 
  35. > could just check the array, could you not?
  36.  
  37. You could, but recursion makes it MUCH easier...  Just do this :
  38.  
  39. Procedure SHOWMINES[X,Y]
  40.  
  41. If GRID(X-1,Y)=0
  42.   SHOWMINES[X-1,Y]
  43. End If
  44. If GRID(X,Y-1)=0
  45.   SHOWMINES[X,Y-1]
  46. End If
  47. If GRID(X+1,Y)=0
  48.   SHOWMINES[X+1,Y]
  49. End If
  50. If GRID(X,Y+1)=0
  51.   SHOWMINES[X,Y+1]
  52. End If
  53. GRID(X,Y)=5
  54.  
  55. End Proc
  56.  
  57. I'm assuming an empty unchecked square contains 0, and that an 
  58. empty 
  59. checked square contains 5.
  60.  
  61. Ain't recursion great?  :)
  62.  
  63. --
  64. GCS -d+ H+ s++:- g+ p? !au a- w+++            !Productions 1995
  65. v* C+++ UB+++A++++ P++ L++ E+ N+++       
  66. http://satelnet.org/~mentat/
  67. K+ !W--- M-- V po- Y+ t++ 5+ jx G?
  68. R tv++ D- B--- e+ u** h f r++ !n y+ "No matter where you go, there 
  69. you are."
  70.  
  71.  
  72.  
  73.  
  74.  
  75.